package com.android.systemui.ios;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import java.lang.ref.SoftReference;

public class SystemGuardService extends Service {

    public static GuardController mController;

    @Override
    public IBinder onBind(Intent intent) {
        return new ExtBinder(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mController = new GuardController(this);
        mController.create();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mController.destroy();
        mController = null;
    }

    public static class ExtBinder extends ISystemGuardService.Stub {

        private final SoftReference<SystemGuardService> mService;

        ExtBinder(SystemGuardService service) {
            mService = new SoftReference<>(service);
        }

        public SystemGuardService getService() {
            return mService.get();
        }

        private GuardController getController() {
            return mService.get().mController;
        }

        @Override
        public void setDisturbEnable(boolean enable) throws RemoteException {
            getController().setDisturbEnable(enable);
        }

        @Override
        public int getBrightnessAutomatic() throws RemoteException {
            return getController().getBrightnessAutomatic();
        }

        @Override
        public void setBrightnessAutomatic(boolean enable) throws RemoteException {
            getController().setBrightnessAutomatic(enable);
        }

        @Override
        public void setBrightnessValue(int value) throws RemoteException {
            getController().setBrightnessValue(value);
        }

        @Override
        public void setBrightnessAdj(float value) throws RemoteException {
            getController().setBrightnessAdj(value);
        }

        @Override
        public void setAirplaneMode(boolean enable) throws RemoteException {
            getController().setAirplaneMode(enable);
        }

        @Override
        public void setDataConnectedEnable(int type) throws RemoteException {
            getController().setDataConnectedEnable(type);
        }

        @Override
        public void setGpsEnable(boolean enable) throws RemoteException {
            getController().setGpsEnable(enable);
        }

        @Override
        public boolean isBluetoothEnabled() throws RemoteException {
            return getController().isBluetoothEnabled();
        }

        @Override
        public void setBluetoothEnabled(boolean enable) throws RemoteException {
            getController().setBluetoothEnabled(enable);
        }

        @Override
        public boolean isHotspotEnabled() throws RemoteException {
            return getController().isHotspotEnabled();
        }

        @Override
        public void setHotspotEnabled(boolean enable) throws RemoteException {
            getController().setHotspotEnabled(enable);
        }

        @Override
        public boolean isWifiEnabled() throws RemoteException {
            return getController().isWifiEnabled();
        }

        @Override
        public void setWifiEnabled(boolean enable) throws RemoteException {
            getController().setWifiEnabled(enable);
        }

        @Override
        public boolean isTorchEnabled() throws RemoteException {
            return getController().isTorchEnabled();
        }

        @Override
        public void setTorchEnabled(boolean enable) throws RemoteException {
            getController().setTorchEnabled(enable);
        }

        @Override
        public void setAudioSilentEnable(boolean enable) throws RemoteException {
            getController().setAudioSilentEnable(enable);
        }

        @Override
        public void setAudioVibrateEnable(boolean enable) throws RemoteException {
            getController().setAudioVibrateEnable(enable);
        }

        @Override
        public void setStreamVolume(int stream, int volume) throws RemoteException {
            getController().setStreamVolume(stream, volume);
        }

        @Override
        public int getRingerMode() throws RemoteException {
            return getController().getRingerMode();
        }

        @Override
        public void setRingerMode(int mode) throws RemoteException {
            getController().setRingerMode(mode);
        }

        @Override
        public int getStreamVolume(int stream) throws RemoteException {
            return getController().getStreamVolume(stream);
        }

        @Override
        public int getStreamMinVolume(int stream) throws RemoteException {
            return getController().getStreamMinVolume(stream);
        }

        @Override
        public int getStreamMaxVolume(int stream) throws RemoteException {
            return getController().getStreamMaxVolume(stream);
        }

        @Override
        public int getBrightnessMin() throws RemoteException {
            return getController().getBrightnessMin();
        }

        @Override
        public int getBrightnessMax() throws RemoteException {
            return getController().getBrightnessMax();
        }

        @Override
        public int getBrightnessCurrent() throws RemoteException {
            return getController().getBrightnessCurrent();
        }

        @Override
        public float getBrightnessAdj() throws RemoteException {
            return getController().getBrightnessAdj();
        }

        @Override
        public int getScreenRecord() throws RemoteException {
            return getController().getScreenRecord();
        }

        @Override
        public void setScreenRecording(boolean start) throws RemoteException {
            getController().setScreenRecording(start);
        }

        @Override
        public boolean isRotationLocked() throws RemoteException {
            return getController().isRotationLocked();
        }

        @Override
        public void setRotationLocked(boolean enable) throws RemoteException {
            getController().setRotationLocked(enable);
        }

        @Override
        public void postRefresh() throws RemoteException {
            getController().postRefresh();
        }

        @Override
        public void sysReboot(String reason) throws RemoteException {
            getController().sysReboot(reason);
        }

        @Override
        public void sysShutdown() throws RemoteException {
            getController().sysShutdown();
        }

        @Override
        public void sysRestore(boolean b1, boolean b2) throws RemoteException {
            getController().sysRestore(b1, b2);
        }

        @Override
        public void sysUpgrade(boolean verify, String file) throws RemoteException {
            getController().sysUpgrade(verify, file);
        }

        @Override
        public void sendKeyEvent(int keyCode, int flags) throws RemoteException {
            getController().sendKeyEvent(keyCode, flags);
        }

        @Override
        public void setNightMode(int mode) throws RemoteException {
            getController().setNightMode(mode);
        }

        @Override
        public int getNightMode() throws RemoteException {
            return getController().getNightMode();
        }

        @Override
        public int execShell(String cmd) throws RemoteException {
            return getController().execShell(cmd);
        }

        @Override
        public void userActivity() throws RemoteException {
            getController().userActivity();
        }

        @Override
        public void setNavVisible(int vis) throws RemoteException {
            getController().setNavVisible(vis);
        }

        @Override
        public int openCamera() throws RemoteException {
            return getController().openCamera();
        }

        @Override
        public int openEmergencyCall() throws RemoteException {
            return getController().openEmergencyCall();
        }

        @Override
        public boolean isLocked() throws RemoteException {
            return getController().isLocked();
        }

        @Override
        public int requestLock(int flag) throws RemoteException {
            return getController().requestLock(flag);
        }

        @Override
        public int requestVerify(String str) throws RemoteException {
            return getController().requestVerify(str);
        }

        @Override
        public int requestFaceRecognition() throws RemoteException {
            return getController().requestFaceRecognition();
        }

        @Override
        public String getProperties(String key, String def) throws RemoteException {
            return getController().getProperties(key, def);
        }

        @Override
        public void setProperties(String key, String value) throws RemoteException {
            getController().setProperties(key, value);
        }

        @Override
        public void setGlobalSettings(String key, String value) throws RemoteException {
            getController().setGlobalSettings(key, value);
        }

        @Override
        public void setSystemSettings(String key, String value) throws RemoteException {
            getController().setSystemSettings(key, value);
        }

        @Override
        public void performNotificationEvent(int action, String pkg, String key) throws RemoteException {
            getController().performNotificationEvent(action, pkg, key);
        }

        @Override
        public void registerStatusChangedCallback(ISystemGuardChangedCallback callback) throws RemoteException {
            getController().registerStatusChangedCallback(callback);
        }

        @Override
        public void unregisterStatusChangedCallback(ISystemGuardChangedCallback callback) throws RemoteException {
            getController().unregisterStatusChangedCallback(callback);
        }

        @Override
        public void registerWindowChangedCallback(IStatusBarWindowChangedCallback callback) throws RemoteException {
            getController().registerWindowChangedCallback(callback);
        }

        @Override
        public void unregisterWindowChangedCallback(IStatusBarWindowChangedCallback callback) throws RemoteException {
            getController().unregisterWindowChangedCallback(callback);
        }
    }
}